package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.News;
import cn.wolfcode.trip.base.domain.NewsComment;
import cn.wolfcode.trip.base.domain.NewsComment;
import cn.wolfcode.trip.base.domain.NewsContent;
import cn.wolfcode.trip.base.mapper.NewsCommentMapper;
import cn.wolfcode.trip.base.query.NewsCommentQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.INewsCommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
@Service
public class NewsCommentServiceImpl implements INewsCommentService {

    @Autowired
    private NewsCommentMapper newsCommentMapper;


    @Override
    public PageInfo<NewsComment> query(NewsCommentQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<NewsComment> list = newsCommentMapper.selectForList(qo);
        return new PageInfo<NewsComment>(list);
    }

    @Override
    public void saveNewsComment(NewsComment newsComment) {
        newsComment.setCommentTime(new Date());
        newsCommentMapper.insert(newsComment);
    }

    @Override
    public PageInfo selectByUserId(NewsCommentQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<NewsComment> list = newsCommentMapper.selectByUserId(qo);
        return new PageInfo<NewsComment>(list);
    }

}
